//
//  MyMessageViewController.m
//  KuWeiPark
//
//  Created by Kevin Su on 15/4/29.
//  Copyright (c) 2015年 Clief. All rights reserved.
//

#import "MyMessageViewController.h"
#import "MyMessageCell.h"

@interface MyMessageViewController ()<UITableViewDataSource, UITableViewDelegate>

@end

@implementation MyMessageViewController{
    
    MyMessageCell *myMessageCell;
    NSArray *messagesArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    myMessageCell = [self.tableView dequeueReusableCellWithIdentifier:@"MyMessageCell"];
    messagesArray = @[@"您的预约已过2小时，车牌号xxxxxx尚未到达车库，xx元订金已扣除。您的预约已失效，如有需要请重新预约。【酷位停车】", @"您的车费订单<订单号156333366>发生错误，停车费20元已经退还到您的 “支付宝”。其他问题还请查看网址：xxxxxx。【酷位停车】", @"我们又来发放停车券，数量有限，快点和你的小伙伴一起来抢吧。网页：xxxxxxxxx【酷位停车】"];
}

#pragma mark - UITableView Delegate && DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return messagesArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSInteger row = indexPath.row;
    myMessageCell.messageContentLabel.text = messagesArray[row];
    CGFloat height = [myMessageCell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    return height + 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 16;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 16)];
    headerView.backgroundColor = [UIColor clearColor];
    return headerView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MyMessageCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MyMessageCell"];
    cell.messageContentLabel.text = messagesArray[indexPath.row];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - IBActions

- (IBAction)back:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}


@end
